#include "/node_modules/lygia/generative/cnoise.glsl"
uniform float iTime;
varying vec2 vUv;
varying float vNoise;
varying vec3 vWorldPosition;
varying vec3 vNormal;

vec3 distort(vec3 p){
    float offset=cnoise(p/8.0+iTime*.5);
    float t=(p.y+offset)*3.1415926*12.;
    float noise=(sin(t)*p.x+cos(t)*p.z)*2.;
    noise*=1.0;
    vNoise=noise;
    p+=noise*normal*.01;
    return p;
}

void main(){
    vec3 p=position;
    vUv=uv;
    float noise=cnoise(p+iTime);
    p+=noise*normal*.1;

    vNormal=normal;
    vWorldPosition=vec3(modelMatrix*vec4(p,1));
    gl_Position=projectionMatrix*modelViewMatrix*vec4(distort(p),1.);
    
    
}